<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class jenis_kendaraan extends My_Controller
{
	
	function __construct()
	{
		parent::__construct();
		
		$this->load->model('mdl_jenis_kendaraan', 'jenis_kendaraan'); 
		$this->load->library('pdf');
		$this->load->library('fungsi');
		
	}
	
	function cokot(){
		echo $this->jenis_kendaraan->get_idjenis_kendaraan();
	}
	
	function index()
	{
		//$data['can_view'] 	= $this->can_view();
		//$data['can_insert'] = $this->can_insert();
		//$data['can_update'] = $this->can_update();
		//$data['can_delete'] = $this->can_delete();
		
		$this->open();
		
		# config pagination
		$config['base_url'] = base_url().'index.php/jenis_kendaraan/index/';
		$config['total_rows'] = $this->db->count_all('t_jeniskb');
		$config['per_page'] = '10';
		$config['num_links'] = '5';
		$config['uri_segment'] = '3';
		
		$config['full_tag_open'] = '';
		$config['full_tag_close'] = '';
		
		$config['num_tag_open'] = '<li>';
		$config['num_tag_close'] = '</li>';
		
		$config['cur_tag_open'] = '<li><a href="javascript:void(0)" class="current">';
		$config['cur_tag_close'] = '</a></li>';
		
		$config['prev_link'] = 'Prev';
		$config['prev_tag_open'] = '<li>';
		$config['prev_tag_close'] = '</li>';
		
		$config['next_link'] = 'Next';
		$config['next_tag_open'] = '<li>';
		$config['next_tag_close'] = '</li>';
		
		$config['last_link'] = 'Last';
		$config['last_tag_open'] = '<li>';
		$config['last_tag_close'] = '</li>';
		
		$config['first_link'] = 'First';
		$config['first_tag_open'] = '<li>';
		$config['first_tag_close'] = '</li>';
		
		$this->pagination->initialize($config);	
		# end config pagination
		
		# get data
		$data['results'] = $this->jenis_kendaraan->getItem($config['per_page'], $this->uri->segment(3));
		
		# load view
		$this->load->view('jenis_kendaraan/jenis_kendaraan_list', $data);
		
		$this->close();
	}
	
	
	function insert()
	{
		//if ($this->can_insert() == FALSE){
		//	redirect('auth/failed');
		//}
		
		$this->open();
		# Data 
		$data['kode'] = $this->input->post('kode');
		$data['uraian'] = $this->input->post('uraian');  
		# set rules validation		 		
		$this->form_validation->set_rules('kode', 'Kode', 'required');		
		$this->form_validation->set_rules('uraian', 'uraian', 'required'); 

		# set message validation		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');		
		$this->form_validation->set_message('required', 'Field %s harus diisi!');
		$this->form_validation->set_message('numeric', 'Field %s harus diisi hanya dengan angka!');
		$this->form_validation->set_message('alpha_dash', 'Field %s harus diisi hanya dengan karakter, angka, underscore, titik!');
		$this->form_validation->set_message('matches', 'Field Password harus sama dengan password confirmasi');
		
		
		if ($this->form_validation->run() == FALSE){
			
			$this->load->view('jenis_kendaraan/jenis_kendaraan_add',$data);
			
		}else{	
			
			// insert ke tabel jenis_kendaraan
			$data_jenis['kode'] = $this->input->post('kode');
			$data_jenis['uraian'] = $this->input->post('uraian'); 
			
			$this->jenis_kendaraan->insert($data_jenis);
			
			$this->session->set_flashdata('message', 'Data Jenis Kendaraan Berhasil disimpan.');
			redirect('jenis_kendaraan');
		}
		
		$this->close();
	}
	
	function update($kode)
	{
		//if ($this->can_update() == FALSE){
		//	redirect('auth/failed');
		//}
		
		$this->open();
		
		$data['result'] 		= $this->jenis_kendaraan->getItemById($kode);
		$data['kode_hidden'] = $kode;				$data['kode'] = $data['result']->row()->kode; 
		$data['uraian'] = $data['result']->row()->uraian; 
		$this->load->view('jenis_kendaraan/jenis_kendaraan_edit', $data);
		
		$this->close();
	}
	
	function process_update()
	{
		//if ($this->can_update() == FALSE){
		//	redirect('auth/failed');
		//}
		
		$this->open();
		
		# Data				$data['kode_hidden'] = $this->input->post('kode_hidden');
		$data['kode'] = $this->input->post('kode'); 
		$data['uraian'] = $this->input->post('uraian');
		 
		
	# set rules validation		 		
		$this->form_validation->set_rules('kode', 'kode', 'required');		
		$this->form_validation->set_rules('uraian', 'uraian', 'required');
		
		$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
		
		# set message validation
		$this->form_validation->set_message('required', 'Field %s harus diisi!');
		$this->form_validation->set_message('alpha', 'Field %s harus diisi hanya dengan huruf!');
		$this->form_validation->set_message('numeric', 'Field %s harus diisi hanya dengan angka!');
		$this->form_validation->set_message('alpha_dash', 'Field %s harus diisi hanya dengan karakter, angka, underscore, titik!');
		$this->form_validation->set_message('matches', 'Field Password harus sama dengan password confirmasi');
		
		
		if ($this->form_validation->run() == FALSE){
			
			$this->load->view('jenis_kendaraan/jenis_kendaraan_edit',$data);
			
		}else{	
			
			// update ke tabel karyawan 			$data['kode_hidden'] = $this->input->post('kode_hidden');			
			$data_jenis['kode'] = $this->input->post('kode');
			$data_jenis['uraian'] = $this->input->post('uraian'); 

			$this->jenis_kendaraan->update($data['kode_hidden'], $data_jenis);
			
			 
			
			$this->session->set_flashdata('message', 'Data Jenis Kendaraan Berhasil diupdate.');
			redirect('jenis_kendaraan');
		}
		
		$this->close();
		
	}
	
	function delete($kode)
	{
		//if ($this->can_delete() == FALSE){
		//	redirect('auth/failed');
		//}
		
		$this->jenis_kendaraan->delete($kode); 
		$this->session->set_flashdata('message', 'Data Jenis Kendaraan Berhasil dihapus.');
		redirect('jenis_kendaraan');
	}
	 	function prepare_report_excel(){		//$data['can_view'] 	= $this->can_view(); 		$data['results'] = $this->jenis_kendaraan->getAll();				# load view		$this->load->view('jenis_kendaraan/jenis_kendaraan_report', $data);	}
	
	function pdf_lap_jenis_kendaraan(){
		
		//$data['results'] = $this->jenis_kendaraan->getAll(false);		$data['results'] = $this->jenis_kendaraan->getAll();
		//$data['num'] = $this->jenis_kendaraan->getAll(true);
		$html=$this->load->view('jenis_kendaraan/jenis_kendaraan_report_pdf', $data, true);
		$this->pdf->pdf_create($html, 'jenis_kendaraan_report_pdf','letter','landscape');
	}
}
